package com.arcsoft.commonbase

import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.MaterialHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import kotlin.properties.Delegates

/**
 *创建人:雷富
 *创建时间:2019/6/5 14:24
 *描述:
 */
abstract class BaseApplication : Application() {

    companion object {
        var context: Context by Delegates.notNull()
        //调试环境
        var debugEnabled = BuildConfig.DEBUG
    }

    //static 代码段可以防止内存泄露
    init {
        //全局设置主题颜色（优先级第二低，可以覆盖 DefaultRefreshInitializer 的配置，与下面的ClassicsHeader绑定）
        SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
            layout.setPrimaryColorsId(R.color.white, R.color.text_color_selected)
            MaterialHeader(context)
        }
        SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout ->
            ClassicsFooter(context).setDrawableSize(20F)
        }
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }

    override fun onCreate() {
        super.onCreate()
        context = applicationContext
        initConfig()
    }


    abstract fun initConfig()


}